import org.apache.hadoop.io.*;
import org.junit.Test;

/**
 * @Author: laoyu
 * @Date: 2020/6/3 17:14
 * @Description:
 */
public class HadoopDataType {
    @Test
    public void testString(){
        String str = "hello hadoop";
        System.out.println(str.length());
        System.out.println(str.indexOf("a"));
        System.out.println(str);
    }

    @Test
    public void testText(){
        Text text = new Text("hello hadoop");
        System.out.println(text.getLength());
        System.out.println(text.find("a"));
        System.out.println(text.toString());
    }

    @Test
    public void testArrayWritable(){
        ArrayWritable arr = new ArrayWritable(IntWritable.class);
        IntWritable i = new IntWritable(2020);
        IntWritable j = new IntWritable(6);
        IntWritable k = new IntWritable(3);
        arr.set(new IntWritable[]{i,j,k});
        System.out.println(
                String.format("i=%d,j=%d,k=%d",
                        ((IntWritable)arr.get()[0]).get(),
                        ((IntWritable)arr.get()[1]).get(),
                        ((IntWritable)arr.get()[2]).get())
        );

    }

    @Test
    public void testMap(){
        MapWritable map = new MapWritable();
        Text k1 = new Text("name");
        Text v1 = new Text("jason");
        Text k2 = new Text("password");

        map.put(k1,v1);
        map.put(k2, NullWritable.get());

        System.out.println(map.get(k1).toString());
        System.out.println(map.get(k2).toString());
    }
}
